package com.jt.demo5.aop;

import com.jt.demo5.anno.Find;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component//将当前类交给Spring容器管理
@Aspect//标注这个一个切面类
public class SpringAOP {
    @Pointcut("@annotation(com.jt.demo5.anno.CGB2108)")
    public void pointcut(){}

/*@Before("pointcut()")*/
    public void before(JoinPoint joinPoint){
        //获取目标对象类型
        Class tergetClass = joinPoint.getTarget().getClass();
        //获取目标对象路径
        String path = joinPoint.getSignature().getDeclaringTypeName();
        //获取目标对象方法名称
        String methodName = joinPoint.getSignature().getName();
        //获取方法参数
        Object[] args = joinPoint.getArgs();
    System.out.println(tergetClass);
    System.out.println(path);
    System.out.println(methodName);
    System.out.println(args);

    }
//    @AfterReturning(value = "pointcut()",returning = "result")
    public void afterReturn(JoinPoint joinPoint,Object result){
        System.out.println("我是后置通知");
    }
   /* @AfterThrowing(value = "pointcut()",throwing = "exception")*/
    public void afterThrow(JoinPoint joinPoint,Exception exception){
        System.out.println("我是异常通知");
    }
    @Before("@annotation(find)")
    public void before1(Find find){
        System.out.println("ID值为"+find.id());
    }








}

